﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DapperWrapper;
using ZilLion.Service.Core.DapperWrapper;

namespace ZLWeb.WebApiRepository.Base
{
    public class SqlConnectionRepository : Respository<SourceContextInstance>
    {
        public void SetDbContext(IDbContext Context) 
        {
            base.SetDbContext(Context);
        }

        public Tuple<IEnumerable<SourceContextInstance>, int> GetDBConnections()
        {
            IEnumerable <SourceContextInstance> items= this.GetList("select * from xtmappingdbconn t1 join xtmappingdbyw t2 on t1.mikvname=t2.mikvname and t1.miidtype=t2.miidtype and t1.miid=t2.miid and t1.miidtype='CRMYwHx'");
            int logsn =this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='xtmappingdbconn'").GetValueOrDefault();
            Tuple<IEnumerable<SourceContextInstance>, int> p2 = new Tuple<IEnumerable<SourceContextInstance>, int>(items, logsn);
            return p2;
        }
        
        public int CheckConnections(int logsn)
        {
            int logsnv2 = this.GetDataByScalar<int>("select MAX(logsn) from xtdatalogcrm where logtable='xtmappingdbconn'").GetValueOrDefault();
            return logsnv2;
        }
    }
}
